package com.lightsaber.trade.as.service.reta;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springside.modules.orm.Page;

import com.lightsaber.trade.as.dao.reta.ProductDao;
import com.lightsaber.trade.as.entity.reta.Product;
import com.lightsaber.trade.core.common.util.CurrentUser;
import com.lightsaber.trade.core.dao.BaseDao;
import com.lightsaber.trade.core.service.BaseServiceImpl;

@Service
@Transactional
public class ProductManager extends BaseServiceImpl<Product, String> {
    @Autowired
    private ProductDao productDao;

    @Override
    protected BaseDao<Product, String> getDao() {
        return productDao;
    }

    public void findPage(Product product, Page<Product> page) {
        productDao.findPage(product, page);
    }

    @Override
    public void save(Product product) {

        if (StringUtils.isBlank(product.getId())) {

            product.setOrganization(CurrentUser.getOrg());
      
        } 
        
        super.save(product);
    }
}
